package com.yfp.operation.utils;

import cn.hutool.core.util.NumberUtil;
import lombok.Data;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description:
 *
 * @CreateDate: 2024/8/16 11:26
 * @UpdateUser:
 * @UpdateDate: 2024/8/16 11:26
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
public class test {
    public static void main(String[] args) {
        jisuan(0);
        jisuan(1);
        jisuan(2);
        jisuan(3);
        jisuan(4);
        count();
    }

    public static void jisuan(int index){
        int[][] samples = init();
        // 初始化一个数组来记录每个数字出现的次数
        int[] count = new int[10];

        // 统计前50组中每个数字出现的次数
        for (int[] sample : samples) {
            count[sample[index]]++;
//            for (int num : sample) {
//                count[num]++;
//            }
        }

        // 计算每个数字的出现概率
        double[] priorProbabilities = new double[10];
        int totalSamples = samples.length * 1; // 假设每组有10个数字
        for (int i = 0; i < count.length; i++) {
            priorProbabilities[i] = (double) count[i] / totalSamples;
        }
        @Data
        class ls{
            private Integer index;
            private double jilv;
        }
        // 现在使用贝叶斯定理来更新第51组的概率
        // 假设第51组的分布是均匀的，每个数字出现的概率应该是相等的
        double uniformPriorProbability = 1.0 / 1; // 因为有10个数字
        double[] posteriorProbabilities = new double[10];
        List<ls> list = new ArrayList<>();
        ls ll = null;
        for (int i = 0; i < priorProbabilities.length; i++) {
            posteriorProbabilities[i] = priorProbabilities[i] * uniformPriorProbability;
            ll = new ls();
            ll.setIndex(i);
            ll.setJilv(posteriorProbabilities[i] );
            list.add(ll);
        }
        Collections.sort(list, Comparator.comparing(s->s.getJilv()));
        System.out.print(index+" ： ");
        int is= 0;
        for (ls ls : list) {
            is=is+1;
            if (is<6){
                System.out.print(ls.getIndex());
            }
        }
//        for (int i = 0; i < posteriorProbabilities.length; i++) {
////            System.out.print(i);
//                    System.out.print(index +": 数字" + i + "的概率: " + posteriorProbabilities[i]);
//        }
        System.out.println(" ");

    }
    /**
     * 次数
     * @return
     */
    public static void count(){
        int[][] init = init();
        Map<Integer, Integer> wanMap = new HashMap<>();
        Map<Integer, Integer> qianMap = new HashMap<>();
        Map<Integer, Integer> baiMap = new HashMap<>();
        Map<Integer, Integer> shiMap = new HashMap<>();
        Map<Integer, Integer> geMap = new HashMap<>();
        for ( int[] ints : init) {
            Integer wan = ints[0];
            Integer i = wanMap.get(wan);
            if (null ==i){
                wanMap.put(wan, 1);
            } else {
                wanMap.put(wan, i+1);
            }

            Integer qian = ints[1];
            Integer c = qianMap.get(qian);
            if (null ==c){
                qianMap.put(qian, 1);
            } else {
                qianMap.put(qian, c+1);
            }

            Integer bai = ints[2];
            Integer b = baiMap.get(wan);
            if (null == b){
                baiMap.put(bai, 1);
            } else {
                baiMap.put(bai, b+1);
            }

            Integer shi = ints[3];
            Integer s = shiMap.get(shi);
            if (null == s){
                shiMap.put(shi, 1);
            } else {
                shiMap.put(shi, s+1);
            }
        }

        for (Integer i : wanMap.keySet()) {
            System.err.println(i+",万位次数："+ wanMap.get(i) +
                    "，千位次数："+ qianMap.get(i) +
                    "，百位次数："+ baiMap.get(i) +
                    "，个位次数："+ shiMap.get(i));
        }

    }

    public static int[][ ] init(){
        int data[][] = new int[][]{
                {4,3,4,8,9}, //1
                {8,1,6,4,6}, //1
                {1,8,4,9,4}, //1
                {3,6,8,9,4}, //2
                {9,1,6,3,0}, //3
                {1,8,8,9,4}, //1
                {0,6,3,9,2}, //2
                {8,1,5,2,6}, //3
                {1,6,8,4,8}, //3
                {4,3,0,6,7}, //1
                {3,5,6,8,5}, //3
                {3,7,6,9,7}, //1
                {9,5,4,1,1}, //1
                {2,7,5,9,3}, //1
                {4,9,8,4,6}, //1
                {2,9,7,6,1}, //1
                {6,9,6,4,9}, //3
                {0,8,8,3,7}, //1
                {9,2,6,1,6}, //1
                {2,7,4,1,2}, //4
                {9,9,5,1,2}, //1
                {2,3,2,3,4}, //1
                {7,5,8,6,3}, //1
                {8,3,5,2,9}, //1
                {5,4,9,1,2}, //1
                {9,9,3,3,8}, //4
                {5,0,0,5,0}, //0
                {7,2,4,1,5}, //4
                {9,7,1,7,0}, //1
                {2,9,1,7,8}, //4
                {1,1,1,0,9}, //4
                {8,4,8,3,9}, //3
                {8,7,7,5,4}, //2
                {1,4,5,3,3}, //2
                {7,3,4,6,2},  //1
                {7,2,7,0,3}, //3
                {6,4,9,7,5}, //0
                {2,8,5,9,1}, //1
                {5,3,5,5,6}, //0
                {9,7,3,7,1}, //4
                {9,8,2,0,5}, //3
                {4,4,6,6,4}, //1
                {2,4,1,6,9}, //2
                {0,4,7,9,4}, //1
                {5,9,2,6,9}, //3
                {1,8,7,0,8}, //3
                {5,1,5,2,2}, //2 
                {3,8,0,7,1}, //2
                {5, 5, 8, 1, 5}, //2
                {5, 5, 0, 0, 3}, //2
                {1, 0, 5, 6, 1}, //2
                {5, 3, 9, 0, 5}, //1
                {5, 1, 7, 0, 4}, //3
                {0, 7, 8, 9, 1}, //2
                {0, 0, 6, 2, 9}, //3
                {3, 4, 0, 7, 1}, //0
                {4, 3, 9, 2, 4}, //1
                {6, 4, 4, 9, 2}, //1
                {7, 9, 3, 2, 2}, //2
                {0, 2, 4, 4, 3}, //3
                {8, 8, 3, 5, 8}, //3
                {3, 6, 7, 3, 4}, //4
                {8, 8, 4, 9, 6}, //3
                {7, 3, 0, 4, 9}, //1
                {5, 0, 0, 9, 5}, //0
                {2, 8, 2, 4, 7}, //3
                {3, 2, 3, 9, 5}, //4
                {2, 1, 5, 4, 9}, //2
                {5, 3, 5, 4, 4}, //0
                {6, 6, 3, 4, 7}, //2
                {5, 7, 9, 8, 2}, //0
                {9, 3, 2, 5, 0}, //2
                {1, 9, 5, 0, 6}, //4
                {1, 9, 1, 8, 5}, //3
                {6, 5, 8, 8, 7}, //2
                {4, 0, 0, 5, 5}, //0
                {0, 7, 0, 7, 8}, //1
                {0, 3, 1, 7, 3}, //3
                {7, 5, 9, 3, 1}, //0
                {5, 4, 1, 5, 7}, //1
                {5, 0, 7, 6, 8}, //1
                {4, 7, 9, 5, 8},
                {9, 3, 2, 9, 4},
                {0, 0, 6, 7, 2},
                {5, 1, 4, 6, 5},
                {3, 2, 0, 4, 4},
                {6, 4, 9, 4, 9},
                {4, 2, 5, 5, 3},
                {4, 3, 0, 6, 7},
                {6, 0, 6, 4, 7},
        };
        return data;
    }

    public static  String[] init2(){
        String data[] = new String[100];
        data[61] = "29178";
        data[62] = "97170";
        data[63] = "72415";
        data[64] = "50050";
        data[65] = "99338";
        data[1] = "11109";
        data[2] = "84839";
        data[3] = "87754";
        data[4] = "14533";
        data[5] = "73462";
        data[6] = "72703";
        data[7] = "64975";
        data[8] = "28591";
        data[9] = "53556";
        data[10] = "97371";
        data[11] = "98205";
        data[12] = "44664";
        data[13] = "24169";
        data[14] = "04794";
        data[15] = "59269";
        data[16] = "18708";
        data[17] = "51522";
        data[18] = "38071";
        data[19] = "55815";
        data[20] = "55003";
        data[21] = "10561";
        data[22] = "53905";
        data[23] = "51704";
        data[24] = "07891";
        data[25] = "00629";
        data[26] = "34071";
        data[27] = "43924";
        data[28] = "64492";
        data[29] = "79322";
        data[30] = "02443";
        data[31] = "88358";
        data[32] = "36734";
        data[33] = "88496";
        data[34] = "73049";
        data[35] = "50095";
        data[36] = "28247";
        data[37] = "32395";
        data[38] = "21549";
        data[39] = "53544";
        data[40] = "66347";
        data[41] = "57982";
        data[42] = "93250";
        data[43] = "19506";
        data[44] = "19185";
        data[45] = "65887";
        data[46] = "40055";
        data[47] = "07078";
        data[48] = "03173";
        data[49] = "75931";
        data[50] = "54157";
        data[51] = "50768";
        data[52] = "47958";
        data[53] = "93294";
        data[54] = "00672";
        data[55] = "51465";
        data[56] = "32044";
        data[57] = "64949";
        data[58] = "42553";
        data[59] = "43067";
        data[60] = "60647";
        return data;
    }

}
